package com.sicong.admin.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sicong.admin.entity.DictItem;
import com.sicong.admin.service.DictItemService;
import com.sicong.common.core.utils.Result;
import com.sicong.common.core.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 字典选项表 前端控制器
 * </p>
 *
 * @author chenww
 * @since 2020-12-31
 */
@Api(tags = {"字典选项控制器"})
@RestController
@RequestMapping("/dictItem")
public class DictItemController {

    @Resource
    private DictItemService dictItemService;

    @ApiOperation("添加字典选项")
    @PostMapping("/save")
    public Result<Void> save(DictItem dictItem) {
        dictItemService.save(dictItem);
        return ResultUtil.success();
    }

    @ApiOperation("删除字典选项")
    @DeleteMapping("/{ids}")
    public Result<Void> removeById(@ApiParam("字典id") @PathVariable String ids) {
        dictItemService.removeById(ids.split(","));
        return ResultUtil.success();
    }

    @ApiOperation("更新字典选项")
    @PutMapping("/update")
    public Result<Void> update(DictItem dictItem) {
        dictItemService.updateById(dictItem);
        return ResultUtil.success();
    }

    @ApiOperation("根据字典查询选项")
    @GetMapping("/{dictId}")
    public Result<List<DictItem>> getDict(@PathVariable Long dictId) {
        List<DictItem> dictItems = dictItemService.list(Wrappers
                .<DictItem>lambdaQuery().eq(DictItem::getDictId, dictId));
        return ResultUtil.success(dictItems);
    }

}

